#!/usr/bin/python  
#-*- coding:utf-8 -*-  
############################  
#File Name: itu.py
#Author: Timy.Huang 
#Mail: timy.huang@foxmail.com  
#Created Time: 2017-06-04 09:15:10
############################  
import xml.etree.ElementTree as ET
import mysql

def search( root_node ):
    database_node = root_node.find("database")
    database = dict()
    for field in database_node:
        database[ field.attrib.get("name") ] = field.text
    fieldsName = root_node.find( "fields" ).attrib[ "name" ]
    fields_node = ET.parse( "/home/htb/zab/service/fields.xml" ).getroot().find( fieldsName )
    fields = []
    for field in fields_node:
        fields.append( field.text )
    limiter = dict()
    limiter_node = root_node.find( "limiter" )
    for field in limiter_node:
        limiter[ field.attrib.get( "name" ) ] = field.text
    return mysql.search( database, fields, limiter )

def getFun( funName ):
    return FUNS[ funName ]


if __name__ == "__main__":
    tree = ET.parse( 'searchtest.xml' )
    root_node = tree.getroot()
    print search( root_node )
